<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" href="static/css/tcommon.css" />
<script src="static/jquery/jquery-1.12.4.js"></script>
<script src="static/easyui/jquery.easyui.min.js"></script>
<script src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<title>预警提示</title>
<style>
.content_table {
	border: 1px solid #8DB2E3
}

.content_table td {
	height: 24px;
	padding: 5px
}

.content_table {
	width: 100%;
	border-collapse: collapse
}

.grid th {
	background: #E7F3FE;
	height: 27px;
	line-height: 27px;
	border: 1px solid #8DB2E3;
	padding-left: 5px
}

.content_table td {
	border: 1px solid #8DB2E3;
	padding-left: 5px
}
</style>
</head>

<body>
<div class="content-container" data-options="region:'center'" >
<div class="panel-header"><div class="panel-title">设备维保预警</div></div>
		<table id="child_table1" class="easyui-datagrid" style="height: 100%"></table>
	</div>

	<div id="proDlg" class="easyui-dialog info_dialog"
		style="width: 600px; padding: 10px 20px; max-height: 600px; overflow-y: auto; top: 30px;" closed="true"
		buttons="#pro-dlg-buttons">
		<div class="title"></div>
		<form id="proFm" method="post">
			<div class="content_container">
				<table class="content_table">
					<tr>
						<td style="width: 150px;">设备维保记录:</td>
						<td>
							<input style="width: 200px;" id="equipment" name="equipment" class="easyui-combobox" editable="false"
								readonly="true" data-options="valueField:'id',textField:'name',panelHeight: 'auto'">
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">是否开机：</td>
						<td>
							<input class="easyui-checkbox" name="isopen" id="isopen" readonly="true">
						</td>
					</tr>
					<tr id="tr1" style="display: none;">
						<td style="width: 100px;">开机时间：</td>
						<td>
							<input class="easyui-datetimebox" id="starttime" name="starttime" style="width: 200px;"
								editable="false" readonly="true" />
						</td>
					</tr>
					<tr id="tr2" style="display: none;">
						<td style="width: 100px;">开机时长（小时）：</td>
						<td>
							<input class="easyui-textbox" id="intervaltime" name="intervaltime" style="width: 200px;"
								data-options="validType:'number'" readonly="true" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">是否维保：</td>
						<td>
							<input class="easyui-checkbox" name="isdaily" id="isdaily" readonly="true">
						</td>
					</tr>
					<tr id="tr3" style="display: none;">
						<td style="width: 100px;">维保时间：</td>
						<td>
							<input class="easyui-datetimebox" id="createtime" name="createtime" style="width: 200px;"
								editable="false" readonly="true" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">备注：</td>
						<td>
							<input class="easyui-textbox" id="remark" name="remark" style="width: 200px;" readonly="true" />
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div id="pro-dlg-buttons">
		<a href="# " class="easyui-linkbutton " onclick="savePro()">已处理</a>
		<a href="# " class="easyui-linkbutton btn-cancel "
			onclick="javascript:$('#proDlg').dialog('close')">取消</a>
	</div>
</body>
<script>
	var currentPro;
	$(document).ready(function() {
		$('#child_table1').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			//title : "设备维保预警",
			url : "warningEquipment.do",
			method : 'get',
			onSelect : function(index,row) {
				currentPro = row;
			},
			columns : [ [ {
				field : 'title',
				title : '项目名',
				width : '',
				formatter : function(value,row,index) {
					if (row.equipment.item){
						return row.equipment.item.name;
					}
				}
			},{
				field : 'equipmentid',
				title : '设备名',
				width : '',
				formatter : function(value,row,index) {
					if (row.equipment){
						return row.equipment.name;
					}
				}
			},{
				field : 'reason',
				title : '原因', 
				width : '',
				formatter : function(value,row,index) {
					if (row.starttime){
						return "开机维保";
					}else{
						return "日常维保";
					}
				}
			},{
				field : 'other',
				title : '查看详情',
				width : '',
				formatter : function(value,row,index) {
					return '<a href="#" style="color:red;" onclick="updatepro(' + index + ');">点击查看</a>';
				}
			} ] ]
		});
	});
	function updatepro(index) {
		$("#proFm").form('clear');
		currentPro = $('#child_table1').datagrid('getRows')[index];
		if (currentPro){
			console.log(currentPro)
			$("#equipment").combobox("setValue", currentPro.equipment.name);
			$("#proFm").form('load', {
				remark : currentPro.remark
			});
			if (currentPro.starttime != null){
				$("#isopen").checkbox('check');
				$("#starttime").datetimebox("setValue", parsedate(currentPro.starttime));
				$("#intervaltime").textbox("setValue", currentPro.intervaltime);
			}
			if (currentPro.isdaily == 1){
				$("#isdaily").checkbox('check');
				$("#createtime").datetimebox("setValue", parsedate(currentPro.createtime));
			}
			$("#proDlg").dialog('open').dialog('setTitle', '设备维保记录');
		}else{
			$.messager.alert('更新', '请选择要更新的设备维保记录', 'warning');
		}
	}
	function savePro() {
		if (!$("#proFm").form('validate'))
			return;
		currentPro.status = 2;
		console.log(currentPro)
		$.ajax({
			type : 'POST',
			url : "equipmentMarkUpdate.do",
			data : JSON.stringify(currentPro),
			contentType : "application/json",
			success : function(data) {
				if (data.success){
					$.messager.show({
						title : '保存',
						msg : '保存成功',
						timeout : 5000,
						showType : 'slide'
					});
					refreshProTable();
				}else{
					$.messager.alert('保存', '保存失败', 'error');
				}
				$('#proDlg').dialog('close');
			},
			dataType : "json"
		});
	}
	function refreshProTable() {
		$('#child_table1').datagrid('reload');
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(),month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(),hour = date.getHours(),min = date.getMinutes(),sec = date.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
	function parsedate(value) {
		var date = new Date(value);
		var year = date.getFullYear();
		var month = date.getMonth() + 1; //月份+1   
		var day = date.getDate();
		var hour = date.getHours();
		var minutes = date.getMinutes();
		var second = date.getSeconds();
		return day + "/" + month + "/" + year + " " + hour + ":" + minutes + ":" + second;
	}
</script>

</html>